import { IFeidaoAiBrowserComponent } from '@feidao/web/interfaces';
import generate from '@feidao/web/atom/browser/url/query2url';

export default async function ca002(fd: IFeidaoAiBrowserComponent, ...args: any[]) {
	// 确定 非日期
	const query = fd.data.params;
	console.log('query', query);
	delete query['page-no'];
	// const q = (query.param || (query.param = {}));
	const param = query.param && JSON.parse(query.param);
	const q = param ? param : {};
	const key = args[0].target.dataset.feidaoId;
	// const input_id = 'input_' + key;
	const check_input = fd.data.node.querySelector('[data-feidao-id=check_' + key + ']') as HTMLInputElement;
	let value = '';
	if (!check_input.checked) {
		const input = fd.data.node.querySelector('[data-feidao-id=input_' + key + ']') as HTMLInputElement;
		const input_value = input.value;
		if (input_value) {
			value = input_value;
			q[key] = value;
			query.param = JSON.stringify(q);

			window.location.href = generate(query);
		}
	} else {
		q[key] = value;

		query.param = JSON.stringify(q);

		window.location.href = generate(query);
	}
}
